<?php
/**
 * Description
 *
 * PHP version 7
 *
 * @category Custom
 * @package  Custom
 * @author   ryu <mo5467@126.com>
 * @date     2020-04-28 22:57:54
 * @lastTime 2020-05-01 23:27:56
 * @license  https://opensource.org/licenses/MIT MIT License
 * @link     none
 */
namespace Test\Unit;

use Design\Behavioral\Memento\State;
use Design\Behavioral\Memento\Ticket;

class MementoState extends \Test\BaseTest
{


    public function testMemento()
    {
        $ticket      = new Ticket();
        $openedState = $ticket->open();

        $this->assertSame(State::STATE_OPENED, (string) $ticket->getState());

        $memento = $ticket->saveToMemento();
        $ticket->assign();
        $this->assertSame(State::STATE_ASSIGNED, (string) $ticket->getState());

        $ticket->restoreFromMemento($memento);
        $this->assertSame(State::STATE_OPENED, (string) $ticket->getState());
        $this->assertNotSame($openedState, $ticket->getState());

        $ticket->close();
        $this->assertSame(State::STATE_CLOSED, (string) $ticket->getState());

    }//end testMemento()

    public function testInvalidState()
    {
        $this->expectException(\InvalidArgumentException::class);

        $state = new State('invalid');
    }


}//end class
